package com.homework;

import java.util.Arrays;
import java.util.Random;

public class Test04 {
    //定义数组，包含10个元素，随机生成数据(范围自拟)，查找最大值和最小值，并输出
    public static void main(String[] args) {
        int[] ints = new int[10];
        Random random = new Random();
        for (int i = 0; i < ints.length; i++) {
            ints[i] = random.nextInt(101);//把随机数赋值给元素,随机数范围为[0,100]
        }
        System.out.println(Arrays.toString(ints));//打印数组

        //遍历新的数组
        int max = ints[0];//假设最大值为ints[0]
        int min = ints[0];//假设最小值为ints[0]
        for (int i = 1; i <= ints.length - 1; i++) {
            if (max < ints[i]) {
                max = ints[i];//把新的最大值赋值给max
            }
            if (min > ints[i]) {
                min = ints[i];//把新的最小值赋值给max
            }
        }
        System.out.println("max = " + max);
        System.out.println("min = " + min);
    }
}
